#ifndef unigame_Time_h
#define unigame_Time_h

#include <time.h>
#include "config/Def.h"

namespace unigame
{
	class Time
	{
	public:
		~Time();

		void update();

		float deltaTime()
		{
			return m_deltaTime;
		}
        
        int64u realDeltaTime()
        {
            return m_realDeltaTime;
        }

		int64u currentRunTime()
		{
			return m_realTime;
		}
        
        float timeScale()
        {
            return m_timeScale;
        }
        
        void timeScale(float scale)
        {
            if(scale < 0)
            {
                scale = 0;
            }
            m_timeScale = scale;
        }
        
        void onPause();
        void onResume();
        
        static Time* instance()
        {
            if(!s_instance)
            {
                s_instance = uni_new Time();
            }
            return s_instance;
        }
        
        static void destroy()
        {
            uni_delete(s_instance);
        }
        
    private:
        Time();
        
	private:
		float m_deltaTime;
        int64u m_realDeltaTime;
		clock_t m_lastTime;
        clock_t m_pauseStartTime;
        int64u m_pauseTime;
        float m_timeScale;
        int64u m_realTime;
        
        static Time* s_instance;
	};
}

#endif